<?

$pageid = "5";
$accessid = "a00";
$title = "Import CSV";
require("required/dbconnect.php");
require("required/function.php");



$errormsg = "";
$uploaddir = "./temp";
$allowed_ext = "csv";
$max_size = "2000000";
$ok = "";
//set_time_limit(800);

if (is_uploaded_file($_FILES['file']['tmp_name']) == true) {
    $extension = pathinfo($_FILES['file']['name']);
    $extension = $extension['extension'];
    $allowed_paths = explode(", ", $allowed_ext);
    for ($i = 0; $i < count($allowed_paths); $i++) {
        if ($allowed_paths[$i] == "$extension") {
            $ok = "1";
        }
    }

    // Check File Size
    if ($ok == "1") {
        if ($_FILES['file']['size'] > $max_size) {


            require("required/header.php");
            ?>            
            <table width="95%" cellpadding="2" cellspacing="1">
                <td valign="top">
                    <font class="title">Import Shipping Data from CSV file</font>
                    <table width="100%">

                        <tr>
                            <td>
                                <font class="dw_failed">Sorry, but the file size must lesser than 2MB</font>
                                <input type="button" value="Back" onclick="history.go(-1)" />

                            </td>
                        </tr>
                    </table>
                </td>
            </table>	

            <?

            require("required/footer.php");
        } else {
            if (is_uploaded_file($_FILES['file']['tmp_name'])) {
                $newname = "csvrecords.csv";
                move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir . '/' . $newname);
            }

            $courier_id = $_POST['courier_id'];
            $group_name = $_POST['group_name'];
            $insert_group = mysql_query("insert into os_shipping_upload_group(group_name,created_datetime)values('$group_name',now())") or die(mysql_error());
            $group_id = mysql_insert_id();


            header("Location:shipping_import3.php?group_name=$group_name&group_id=$group_id&courier_id=$courier_id");
        }
    } else {
        header("Location:shipping_import.php?dispmsg=invalid_file_format");
    }
}else{
    header("Location:shipping_import.php?dispmsg=no_file_selected");
}
?>		

